package com.yidu.hbatsams.service.TrainingPlan.zjj;


import com.yidu.hbatsams.dao.AtsPlanCurriculumMapper;
import com.yidu.hbatsams.domain.AtsBaseItem;
import com.yidu.hbatsams.domain.AtsDataDic;
import com.yidu.hbatsams.domain.AtsPlanCurriculum;
import com.yidu.hbatsams.domain.AtsPlanItem;
import com.yidu.hbatsams.service.AtsBaseItemService;
import com.yidu.hbatsams.service.AtsDataDicSerivce;
import com.yidu.hbatsams.service.TrainingPlan.AtsPlanItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: hbats
 * @description
 * @author: 周佳佳
 * @create: 2019-12-11 10:05
 **/
@Service
public class PlanCurriculumServiceImpl implements PlanCurriculumService {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    AtsPlanCurriculumMapper planCurriculumMapper;
    @Resource
    AtsPlanItemService atsPlanItemService;
    @Resource
    AtsBaseItemService atsBaseItemService;
    @Resource
    AtsDataDicSerivce atsDataDicSerivce;

    @Override
    public void insertSelectiveFour(AtsPlanCurriculum planCurriculum, String[] numArr) {
        Date utilDate = new Date();//util.Date
        java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
        //传入创建视剧
        planCurriculum.setCreatTime(sqlDate);
        //登录人当教练名字
        planCurriculum.setCoachName(planCurriculum.getCreater());

        planCurriculumMapper.insertSelective(planCurriculum);
        //new出指标的模型
        AtsPlanItem atsPlanItem=new AtsPlanItem();
        atsPlanItem.setIsva(1);
        Date utilDate1 = new Date();//util.Date
        java.sql.Date sqlDate1 = new java.sql.Date(utilDate1.getTime());
        //传入创建视剧
        atsPlanItem.setCreatTime(sqlDate1);
        //传入1代表课
        atsPlanItem.setPlandate("1");
        //传入创建人
        atsPlanItem.setCreater(planCurriculum.getCreater());
        //传入课id
        atsPlanItem.setPid(planCurriculum.getCurriculumId());
        //传入课的名称
        atsPlanItem.setPname(planCurriculum.getCurriculumName());

    }

    @Override
    public List<AtsPlanCurriculum> selectByDate(Integer coachId) {
        String planDate=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return planCurriculumMapper.selectByDate(planDate,coachId);
    }

    @Override
    public List<AtsPlanCurriculum> selectCurricu(int weekId) {
        return planCurriculumMapper.selectCurricu(weekId);
    }

    @Override
    public AtsPlanCurriculum findById(int curriculumId) {
        return planCurriculumMapper.findById(curriculumId);
    }

    @Override
    public int selectWeekcount() {
        return planCurriculumMapper.selectWeekcount();
    }

    @Override
    public AtsPlanCurriculum selectByIsvaTwo(Integer weekId) {
        return planCurriculumMapper.selectByIsvaTwo(weekId);
    }

    @Override
    public int updateZancunIsva(AtsPlanCurriculum atsPlanCurriculum) {
        return planCurriculumMapper.updateZancunIsva(atsPlanCurriculum);
    }

    @Override
    public void updatePlancurricu(AtsPlanCurriculum atsPlanCurriculum,String[] numArr) {
        //new出指标的模型
        AtsPlanItem atsPlanItemone=new AtsPlanItem();
        //修改时传入1代表课计划
        atsPlanItemone.setPlandate("1");
        atsPlanItemone.setPid(atsPlanCurriculum.getCurriculumId());
        atsPlanItemone.setIsva(0);
        atsPlanItemService.updatecurriculumItem(atsPlanItemone);
        if(!StringUtils.isEmpty(numArr)){
            //new出指标的模型
            AtsPlanItem atsPlanItem=new AtsPlanItem();
            //传入1代表课计划
            atsPlanItem.setPlandate("1");
            atsPlanItem.setIsva(1);
            Date utilDate1 = new Date();//util.Date
            java.sql.Date sqlDate1 = new java.sql.Date(utilDate1.getTime());
            //传入创建视剧
            atsPlanItem.setCreatTime(sqlDate1);
            //传入创建人
            atsPlanItem.setCreater(atsPlanCurriculum.getCreater());
            //传入课id
            atsPlanItem.setPid(atsPlanCurriculum.getCurriculumId());
            //传入课的名称
            atsPlanItem.setPname(atsPlanCurriculum.getCurriculumName());

        }
        planCurriculumMapper.updateIsva(atsPlanCurriculum);
    }

    @Override
    public AtsPlanCurriculum selectMaxcurruculum(Integer weekId) {
        return planCurriculumMapper.selectMaxcurruculum(weekId);
    }

    @Override
    public int updateIsva(AtsPlanCurriculum atsPlanCurriculum) {
        return planCurriculumMapper.updateIsva(atsPlanCurriculum);
    }

    @Override
    public int countFive(AtsPlanCurriculum atsPlanCurriculum) {
        return planCurriculumMapper.countFive(atsPlanCurriculum);
    }


}
